# encoding: UTF-8
 
class Admin::GuidesController < ApplicationController
  
  before_filter :user_signed_in?
  
  def index
    @guides = Guide.paginate(:page => params[:page], :per_page => '13')
    set_seo_meta '游戏指南'
  end

  def new
    @level = Level.open_status
    set_seo_meta '增加游戏指南'
  end
  
  def create
    @guide = Guide.new(params[:session])
    if @guide.save!
      redirect_to guides_path, notice: '新增成功!'
    else
      redirect_referrer_or_default default
    end  
  end

  def edit
    @level = Level.open_status
    @guide = Guide.find(params[:id]) 
    set_seo_meta '内容修改'
  end

  def update
    @guide = Guide.find(params[:id])
    if @guide.update_attributes!(params[:session])
      redirect_to guides_path, notice:'修改成功'
    else
      redirect_referrer_or_defautl default
    end
  end

  def destroy
    if Guide.delete(params[:id])
      redirect_to guides_path, notice:'删除成功'
    else
      redirect_referrer_or_default default
    end  
  end

end
